<?php
$sanitize_all_escapes = true;
$fake_register_globals = false;

require_once("../../globals.php");
require_once("$srcdir/forms.inc");
require_once("$srcdir/calendar.inc");
require_once("$srcdir/acl.inc");
require_once("$srcdir/formatting.inc.php");
require_once("$srcdir/patient.inc");
require_once("$srcdir/amc.php");
include_once("$srcdir/pid.inc");
include_once("$srcdir/encounter.inc");
require_once("$srcdir/patient_provider.inc.php");

if (isset($_GET["set_encounter"])) {
    // The billing page might also be setting a new pid.
    $set_pid = $_GET["set_pid"] ? $_GET["set_pid"] : $_GET["pid"];
    if ($set_pid && $set_pid != $_SESSION["pid"]) {
        setpid($set_pid);
    }
    setencounter($_GET["set_encounter"]);
}
?>
<html>

    <head>
        <link rel="stylesheet" type="text/css" href="<?php echo $GLOBALS['webroot'] ?>/interface/themes/style_metal.css">
        <link rel="stylesheet" type="text/css" href="<?php echo $GLOBALS['webroot'] ?>/interface/themes/nightingale.css" media="screen"/>
        <link rel="stylesheet" type="text/css" href="<?php echo $GLOBALS['webroot'] ?>/interface/themes/jquery.fancybox.css?v=2.1.5" media="screen"/>
        <style type="text/css">@import url(<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar.css);</style>

        <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery-1.9.1.min.js"></script>
        <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.fancybox.pack.js"></script>
        <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/expand.js"></script>
        <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js"></script>
        <script language="JavaScript">
            $(function() {
                $("#encounter_forms h3.expand").toggler({method: "toggle", speed: 0});
                $("#encounter_forms div.eventos").expandAll({trigger: "h3.expand", ref: "h3.expand", speed: 0});
            });

            // Process click on Delete link.
            function deleteme() {
                dlgopen('del_consulta', '../patient_file/deleter.php?encounterid=<?php echo $encounter; ?>', '_blank', 500, 450);
                return false;
            }

            // Called by the deleter.php window on a successful delete.
            function imdeleted(EncounterId) {
<?php if ($GLOBALS['concurrent_layout']) { ?>
            top.window.parent.left_nav.removeOptionSelected(EncounterId);
            top.window.parent.left_nav.clearEncounter();
<?php } else { ?>
            top.restoreSession();
            top.Title.location.href = '../patient_file/encounter/encounter_title.php';
            top.Main.location.href = '../patient_file/encounter/patient_encounter.php?mode=new';
<?php } ?>
    }

    $(document).ready(function() {
        $('.iframeConsulta').click(function(e) {
            e.preventDefault();
            parent.$.fancybox({
                href: this.href,
                autoSize: false,
                type: 'iframe',
                helpers: {
                    overlay: {
                        opacity: 0.3,
                        css: {
                            'background': 'rgba(255, 254, 254,0.85)'
                        }
                    } // overlay
                }, // helpers
                afterClose: function() {
<?php if (isset($_GET["set_encounter"])) { ?>
                        $("#column_left").load("../patient_file/encounter/forms.php?set_encounter=" + <?php echo $_GET["set_encounter"]; ?>);
<?php } ?>
                }//afterClose
            }); // fancybox
        }); // click

        $('#procedimiento').click(function(e) {
            e.preventDefault();
            $("#column_left").load("<?php echo $rootdir . '/patient_file/encounter/load_form.php?formname=procedure_order&set_encounter=' . $_GET["set_encounter"] ?>");

        });

        $('.iframeSignos').click(function(e) {
            e.preventDefault();
            parent.$.fancybox({
                href: this.href,
                autoSize: false,
                type: 'iframe',
                helpers: {
                    overlay: {
                        opacity: 0.3,
                        css: {
                            'background': 'rgba(255, 254, 254,0.85)'
                        }
                    } // overlay
                }, // helpers
                afterClose: function() {
<?php if (isset($_GET["set_encounter"])) { ?>
                        $("#column_left").load("../patient_file/encounter/forms.php?set_encounter=" + <?php echo $_GET["set_encounter"]; ?>, function() {
                            $("#signos").load("../patient_file/summary/vitals_fragment.php");
                        });
<?php } ?>
                }//afterClose
            }); // fancybox
        }); // click

        $('.iframe_del').click(function(e) {
            e.preventDefault();
            parent.$.fancybox({
                href: this.href,
                autoSize: true,
                type: 'iframe',
                helpers: {
                    overlay: {
                        opacity: 0.3,
                        css: {
                            'background': 'rgba(255, 254, 254,0.85)'
                        }
                    } // overlay
                }
            }); // fancybox
        }); // click

        //Volver al timeline
        $('#enc_list').click(function(e) {
            e.preventDefault();
            $("#column_left").load("../patient_file/summary/get_encounters.php");
        }); // click

        $(".switch a").click();
    });
        </script>
    </head>

    <body>
        <div id="consulta_medica" class="border">
            <?php
            //DYNAMIC FORM RETREIVAL
            include_once("$srcdir/registry.inc");

            function myGetRegistered($state = "1", $limit = "unlimited", $offset = "0") {
                $sql = "SELECT category, nickname, name, state, directory, id, sql_run, " .
                        "unpackaged, date FROM registry WHERE " .
                        "state LIKE \"$state\" ORDER BY category, priority, name";
                if ($limit != "unlimited")
                    $sql .= " limit $limit, $offset";
                $res = sqlStatement($sql);
                if ($res) {
                    for ($iter = 0; $row = sqlFetchArray($res); $iter++) {
                        $all[$iter] = $row;
                    }
                } else {
                    return false;
                }
                return $all;
            }

            $reg = myGetRegistered();

            if (!empty($reg)) {
                $StringEcho = '<ul id="submenu">';
                foreach ($reg as $entry) {
                    /* echo "<pre>";
                      print_r($entry);
                      echo "</pre>"; */
                    $new_nickname = trim($entry['nickname']);
                    if ($new_nickname != '') {
                        $nickname = $new_nickname;
                    } else {
                        $nickname = $entry['name'];
                    }
                    if ($entry['directory'] != 'newpatient') {

                        if ($entry['directory'] == 'procedure_order') {
                            $StringEcho.= "<a href='#' title='" . xl_form_title($nickname) . "' ";
                            $StringEcho.="class='' id='procedimiento'><i class='icon-check'></i>";
                        }
                        if ($entry['directory'] == 'vitals') {
                            $StringEcho.= "<a href='" . $rootdir . '/patient_file/encounter/load_form.php?formname=' . urlencode($entry['directory']) .
                                    "' title='" . xl_form_title($nickname) . "' ";
                            $StringEcho.="class='iframeSignos'><i class='icon-gittip'></i>";
                        }
                        if ($entry['directory'] == 'physical_exam') {
                            $StringEcho.= "<a href='" . $rootdir . '/patient_file/encounter/load_form.php?formname=' . urlencode($entry['directory']) .
                                    "' title='" . xl_form_title($nickname) . "' ";
                            $StringEcho.="class='iframeConsulta'><i class='icon-male'></i>";
                        }
                        $StringEcho.="</a>";
                    }
                }
            }

            $lres = sqlStatement("SELECT * FROM list_options " .
                    "WHERE list_id = 'lbfnames' ORDER BY seq, title");
            if (sqlNumRows($lres)) {
                while ($lrow = sqlFetchArray($lres)) {
                    $option_id = $lrow['option_id']; // should start with LBF
                    $title = $lrow['title'];
                    $StringEcho.= "<a href='" . $rootdir . '/patient_file/encounter/load_form.php?formname='
                            . urlencode($option_id) . "' title='" . xl_form_title($title) . "' ";
                    /* echo "<pre>";
                      print_r($lrow);
                      echo "</pre>"; */
                    if ($lrow['option_id'] == 'LBFComposicion_corporal') {
                        $StringEcho.="class='iframeConsulta'><i class='icon-question-sign'></i>";
                    }
                    if ($lrow['option_id'] == 'LBFExamenVista') {
                        $StringEcho.="class='iframeConsulta'><i class='icon-eye-open'></i>";
                    }
                    if ($lrow['option_id'] == 'LBFelectrocardiograma') {
                        $StringEcho.="class='iframeConsulta'><i class='icon-bolt'></i>";
                    }
                    $StringEcho.="</a>";
                }
            }

            $StringEcho.= '<a id="enc_list" title="Regresar" href="#"><i class="icon-undo"></i></a>';

            $dateres = getEncounterDateByEncounter($encounter);
            $encounter_date = date("Y-m-d", strtotime($dateres["date"]));
            $providerIDres = getProviderIdOfEncounter($encounter);
            $providerNameRes = getProviderName($providerIDres);

            $auth_notes_a = acl_check('encounters', 'notes_a');
            $auth_notes = acl_check('encounters', 'notes');
            $auth_relaxed = acl_check('encounters', 'relaxed');

            if (is_numeric($pid)) {
                // Check for no access to the patient's squad.
                $result = getPatientData($pid, "fname,lname,squad");

                if ($result['squad'] && !acl_check('squads', $result['squad'])) {
                    $auth_notes_a = $auth_notes = $auth_relaxed = 0;
                }
                // Check for no access to the encounter's sensitivity level.
                $result = sqlQuery("SELECT sensitivity FROM form_encounter WHERE " .
                        "pid = '$pid' AND encounter = '$encounter' LIMIT 1");
                if ($result['sensitivity'] && !acl_check('sensitivities', $result['sensitivity'])) {
                    $auth_notes_a = $auth_notes = $auth_relaxed = 0;
                }
            }

            if ($GLOBALS['enable_amc_prompting']) {
                ?>
                <!--
                <div class='divEncuesta'>
                                <table>
                                <tr>
                                        <td>
                <?php
                // Display the education resource checkbox (AMC prompting)
                $itemAMC = amcCollect("patient_edu_amc", $pid, 'form_encounter', $encounter);
                ?>
                <?php if (!(empty($itemAMC))) { ?>
                                                                                                                                    <input type="checkbox" id="prov_edu_res" checked>
                <?php } else { ?>
                                                                                                                                    <input type="checkbox" id="prov_edu_res">
                <?php } ?>
                                        </td>
                                        <td>
                                                <span class="text"><?php echo xl('Provided Education Resource(s)?') ?></span>
                                        </td>
                                </tr>
                                <tr>
                                        <td>
                <?php
                // Display the Provided Clinical Summary checkbox (AMC prompting)
                $itemAMC = amcCollect("provide_sum_pat_amc", $pid, 'form_encounter', $encounter);
                ?>
                <?php if (!(empty($itemAMC))) { ?>
                                                                                                                                    <input type="checkbox" id="provide_sum_pat_flag" checked>
                <?php } else { ?>
                                                                                                                                    <input type="checkbox" id="provide_sum_pat_flag">
                <?php } ?>
                                        </td>
                                        <td>
                                                <span class="text"><?php echo xl('Provided Clinical Summary?') ?></span>
                                        </td>
                                </tr>
                <?php
                // Display the medication reconciliation checkboxes (AMC prompting)
                $itemAMC = amcCollect("med_reconc_amc", $pid, 'form_encounter', $encounter);
                ?>
                <?php if (!(empty($itemAMC))) { ?>
                                                                                                                    <tr>
                                                                                                                            <td>
                                                                                                                                    <input type="checkbox" id="trans_trand_care" checked>
                                                                                                                            </td>
                                                                                                                            <td>
                                                                                                                                    <span class="text"><?php echo xl('Transition/Transfer of Care?') ?></span>
                                                                                                                            </td>
                                                                                                                    </tr>
                                                                                                            </table>
                                                                                                            <table style="margin-left:2em;">
                                                                                                                    <tr>
                                                                                                                            <td>
                    <?php if (!(empty($itemAMC['date_completed']))) { ?>
                                                                                                                                                                                                                    <input type="checkbox" id="med_reconc_perf" checked>
                    <?php } else { ?>
                                                                                                                                                                                                                    <input type="checkbox" id="med_reconc_perf">
                    <?php } ?>
                                                                                                                            </td>
                                                                                                                            <td>
                                                                                                                                    <span class="text"><?php echo xl('Medication Reconciliation Performed?') ?></span>
                                                                                                                            </td>
                                                                                                                    </tr>
                                                                                                            </table>
                <?php } else { ?>
                                                                                                            <tr>
                                                                                                                    <td>
                                                                                                                            <input type="checkbox" id="trans_trand_care">
                                                                                                                    </td>
                                                                                                                    <td>
                                                                                                                            <span class="text"><?php echo xl('Transition/Transfer of Care?') ?></span>
                                                                                                                    </td>
                                                                                                            </tr>
                                                                                                            </table>
                                                                                                            <table style="margin-left:2em;">
                                                                                                                    <tr>
                                                                                                                            <td>
                                                                                                                                    <input type="checkbox" id="med_reconc_perf" DISABLED>
                                                                                                                            </td>
                                                                                                                            <td>
                                                                                                                                    <span class="text"><?php echo xl('Medication Reconciliation Performed?') ?></span>
                                                                                                                            </td>
                                                                                                                    </tr>
                                                                                                            </table>
                <?php } ?>
                </div>
                -->
            <?php } ?>

            <div id="toolBar"><?php echo $StringEcho; ?></div>

            <div id="encounter_forms">  
                <div class="eventos">
                    <h2 style="color: rgb(255, 255, 255); padding-left: 10px;">
                        <i class="icon-stethoscope" style="font-size: 25px;"></i> Consulta M&eacute;dica - david<span class="title"><?php echo oeFormatShortDate($encounter_date); ?> </span>
                        <?php if (acl_check('admin', 'super')) { ?>
                            <a onclick="return deleteme()" class="css_button_left iframe_del" id="del_consulta" href="#" style="border-style: solid;"><i class="icon-remove"></i></a>
                        <?php } ?>
                    </h2>

                    <?php
                    if ($result = getFormByEncounter($pid, $encounter, "id, date, form_id, form_name, formdir, user, deleted")) {
                        $divnos = 1;
                        $existe = false;
                        $form_name = "";
                        $user = "";
                        foreach ($result as $iter) {
                            $existeAutorizacionMedicoInfoPacientesUsuario = existeAutorizacionMedicoInfoPacientesUsuario($iter['user']);

                            $formdir = $iter['formdir'];
                            if ($formdir === 'procedure_order') {

                                if ($iter['deleted'] == 1)
                                    continue;

                                // Skip forms that we are not authorized to see.
                                if (($existeAutorizacionMedicoInfoPacientesUsuario) || ($auth_notes_a) ||
                                        ($auth_notes && $iter['user'] == $_SESSION['authUser']) ||
                                        ($auth_relaxed && ($formdir == 'sports_fitness' || $formdir == 'podiatry')))
                                    ;
                                else
                                    continue;
                                $form_name = ($formdir == 'newpatient') ? "Resumen"/* xl('Patient Encounter') */ : xl_form_title($iter['form_name']);
                                $user = getNameFromUsername($iter['user']);
                                $existe = true;
                            }
                        }
                        if ($existe) {
                            echo "<h3 class='expand'>";

                            $form_author = $user['fname'] . "  " . $user['lname'];

                            echo "<b>$form_name</b> <span class='text'>por " . htmlspecialchars($form_author) . "</span>";
                            echo "</h3>";
                            echo "<div class='collapse divConsulta' id='divid_$divnos'>";
                            foreach ($result as $iter) {
                                $formdir = $iter['formdir'];
                                if ($formdir === 'procedure_order') {
                                    $existeAutorizacionMedicoInfoPacientesUsuario = existeAutorizacionMedicoInfoPacientesUsuario($iter['user']);
                                    // skip forms whose 'deleted' flag is set to 1
                                    if ($iter['deleted'] == 1)
                                        continue;

                                    // Skip forms that we are not authorized to see.
                                    if (($existeAutorizacionMedicoInfoPacientesUsuario) || ($auth_notes_a) ||
                                            ($auth_notes && $iter['user'] == $_SESSION['authUser']) ||
                                            ($auth_relaxed && ($formdir == 'sports_fitness' || $formdir == 'podiatry')))
                                        ;
                                    else
                                        continue;

                                    echo "<div class='divConsulta'>";
                                    // $form_info = getFormInfoById($iter['id']);
                                    if (strtolower(substr($iter['form_name'], 0, 5)) == 'camos') {
                                        echo '<tr title="' . xl('Edit form') . '" ' .
                                        'id="' . $formdir . '~' . $iter['form_id'] . '">';
                                    } else {
                                        echo '<tr title="' . xl('Edit form') . '" ' .
                                        'id="' . $formdir . '~' . $iter['form_id'] . '" class="text onerow">';
                                    }


                                    // Skip forms that we are not authorized to see.
                                    if (($auth_notes_a) ||
                                            ($auth_notes && $iter['user'] == $_SESSION['authUser']) ||
                                            ($auth_relaxed && ($formdir == 'sports_fitness' || $formdir == 'podiatry')))
                                        echo "<a href='$rootdir/patient_file/encounter/view_form.php?" .
                                        "formname=" . $formdir . "&id=" . $iter['form_id'] . "' class='css_button iframeConsulta'><i class='icon-edit'></i></a>";

                                    if (acl_check('admin', 'super')) {
                                        if ($formdir != 'newpatient') {
                                            // a link to delete the form from the encounter
                                            echo "<a href='$rootdir/patient_file/encounter/delete_form.php?" .
                                            "formname=" . $formdir .
                                            "&id=" . $iter['id'] .
                                            "&encounter=" . $encounter .
                                            "&pid=" . $pid .
                                            "' class='css_button ";
                                            if ($formdir == 'vitals') {
                                                echo "iframeSignos";
                                            } else {
                                                echo "iframeConsulta";
                                            }
                                            echo "' title='" . xl('Delete this form') . "'><i class='icon-remove'></i></a>";
                                        }
                                    }

                                    if (substr($formdir, 0, 3) == 'LBF') {
                                        include_once($GLOBALS['incdir'] . "/forms/LBF/report.php");
                                        call_user_func("lbf_report", $pid, $encounter, 2, $iter['form_id'], $formdir);
                                    } else {
                                        include_once($GLOBALS['incdir'] . "/forms/$formdir/report.php");
                                        call_user_func($formdir . "_report", $pid, $encounter, 2, $iter['form_id']);
                                    }
                                    echo "</div>";
                                }
                            }
                            echo "</div>";
                            $divnos = $divnos + 1;
                        }
                        foreach ($result as $iter) {
                            $existeAutorizacionMedicoInfoPacientesUsuario = existeAutorizacionMedicoInfoPacientesUsuario($iter['user']);

                            $formdir = $iter['formdir'];
                            if ($formdir !== 'procedure_order') {
                                // skip forms whose 'deleted' flag is set to 1
                                if ($iter['deleted'] == 1)
                                    continue;

                                // Skip forms that we are not authorized to see.
                                if ($existeAutorizacionMedicoInfoPacientesUsuario || ($auth_notes_a) ||
                                        ($auth_notes && $iter['user'] == $_SESSION['authUser']) ||
                                        ($auth_relaxed && ($formdir == 'sports_fitness' || $formdir == 'podiatry')))
                                    ;
                                else
                                    continue;

                                // $form_info = getFormInfoById($iter['id']);
                                if (strtolower(substr($iter['form_name'], 0, 5)) == 'camos') {
                                    //CAMOS generates links from report.php and these links should
                                    //be clickable without causing view.php to come up unexpectedly.
                                    //I feel that the JQuery code in this file leading to a click
                                    //on the report.php content to bring up view.php steps on a
                                    //form's autonomy to generate it's own html content in it's report
                                    //but until any other form has a problem with this, I will just
                                    //make an exception here for CAMOS and allow it to carry out this
                                    //functionality for all other forms.  --Mark
                                    echo '<tr title="' . xl('Edit form') . '" ' .
                                    'id="' . $formdir . '~' . $iter['form_id'] . '">';
                                } else {
                                    echo '<tr title="' . xl('Edit form') . '" ' .
                                    'id="' . $formdir . '~' . $iter['form_id'] . '" class="text onerow">';
                                }
                                $user = getNameFromUsername($iter['user']);

                                $form_name = ($formdir == 'newpatient') ? "Resumen"/* xl('Patient Encounter') */ : xl_form_title($iter['form_name']);


                                echo "<h3 class='expand'>";
                                // Figure out the correct author (encounter authors are the '$providerNameRes', while other
                                // form authors are the '$user['fname'] . "  " . $user['lname']').
                                if ($formdir == 'newpatient') {
                                    $form_author = $providerNameRes;
                                } else {
                                    $form_author = $user['fname'] . "  " . $user['lname'];
                                }
                                echo "<b>$form_name</b> <span class='text'>por " . htmlspecialchars($form_author) . "</span>";
                                echo "</h3>";
                                echo "<div class='collapse divConsulta' id='divid_$divnos'>";

                                $last = $form_name;


                                if (($auth_notes_a) ||
                                        ($auth_notes && $iter['user'] == $_SESSION['authUser']) ||
                                        ($auth_relaxed && ($formdir == 'sports_fitness' || $formdir == 'podiatry')))
                                    echo "<a href='$rootdir/patient_file/encounter/view_form.php?" .
                                    "formname=" . $formdir . "&id=" . $iter['form_id'] . "' class='css_button iframeConsulta'><i class='icon-edit'></i></a>";

                                if (acl_check('admin', 'super')) {
                                    if ($formdir != 'newpatient') {
                                        // a link to delete the form from the encounter
                                        echo "<a href='$rootdir/patient_file/encounter/delete_form.php?" .
                                        "formname=" . $formdir .
                                        "&id=" . $iter['id'] .
                                        "&encounter=" . $encounter .
                                        "&pid=" . $pid .
                                        "' class='css_button ";
                                        if ($formdir == 'vitals') {
                                            echo "iframeSignos";
                                        } else {
                                            echo "iframeConsulta";
                                        }
                                        echo "' title='" . xl('Delete this form') . "'><i class='icon-remove'></i></a>";
                                    } /* else {
                                      ?><a href='javascript:;' class='css_button_small' style='color:gray'><?php xl('Delete', 'e'); ?></a><?php
                                      } */
                                }

                                // Use the form's report.php for display.  Forms with names starting with LBF
                                // are list-based forms sharing a single collection of code.
                                //
                            if (substr($formdir, 0, 3) == 'LBF') {
                                    include_once($GLOBALS['incdir'] . "/forms/LBF/report.php");
                                    call_user_func("lbf_report", $pid, $encounter, 2, $iter['form_id'], $formdir);
                                } else {
                                    include_once($GLOBALS['incdir'] . "/forms/$formdir/report.php");
                                    call_user_func($formdir . "_report", $pid, $encounter, 2, $iter['form_id']);
                                }

                                echo "</div>";
                                $divnos = $divnos + 1;
                            }
                        }
                    }
                    ?>
                </div>
            </div>
        </div> <!-- consulta medica -->
    </body>

    <script language="javascript">
        // jQuery stuff to make the page a little easier to use

        /* $(document).ready(function() {
             $(".save").click(function() {
             top.restoreSession();
             document.my_form.submit();
             });
             $(".dontsave").click(function() {
             location.href = '<?php echo "$rootdir/patient_file/encounter/$returnurl"; ?>';
             });
             
             $(".onerow").mouseover(function() {
             $(this).toggleClass("highlight");
             });
             $(".onerow").mouseout(function() {
             $(this).toggleClass("highlight");
             });
             $(".onerow").click(function() {
             GotoForm(this);
             });
             
             $("#prov_edu_res").click(function() {
             if ($('#prov_edu_res').attr('checked')) {
             var mode = "add";
             }
             else {
             var mode = "remove";
             }
             top.restoreSession();
             $.post("<?php echo $GLOBALS['webroot'] ?>/library/ajax/amc_misc_data.php",
             {amc_id: "patient_edu_amc",
             complete: true,
             mode: mode,
             patient_id: <?php echo htmlspecialchars($pid, ENT_NOQUOTES); ?>,
             object_category: "form_encounter",
             object_id: <?php echo htmlspecialchars($encounter, ENT_NOQUOTES); ?>
             }
             );
             });
             
             $("#provide_sum_pat_flag").click(function() {
             if ($('#provide_sum_pat_flag').attr('checked')) {
             var mode = "add";
             }
             else {
             var mode = "remove";
             }
             top.restoreSession();
             $.post("<?php echo $GLOBALS['webroot'] ?>/library/ajax/amc_misc_data.php",
             {amc_id: "provide_sum_pat_amc",
             complete: true,
             mode: mode,
             patient_id: <?php echo htmlspecialchars($pid, ENT_NOQUOTES); ?>,
             object_category: "form_encounter",
             object_id: <?php echo htmlspecialchars($encounter, ENT_NOQUOTES); ?>
             }
             );
             });
             
             $("#trans_trand_care").click(function() {
             if ($('#trans_trand_care').attr('checked')) {
             var mode = "add";
             // Enable the reconciliation checkbox
             $("#med_reconc_perf").removeAttr("disabled");
             }
             else {
             var mode = "remove";
             //Disable the reconciliation checkbox (also uncheck it if applicable)
             $("#med_reconc_perf").attr("disabled", true);
             $("#med_reconc_perf").removeAttr("checked");
             }
             top.restoreSession();
             $.post("<?php echo $GLOBALS['webroot'] ?>/library/ajax/amc_misc_data.php",
             {amc_id: "med_reconc_amc",
             complete: false,
             mode: mode,
             patient_id: <?php echo htmlspecialchars($pid, ENT_NOQUOTES); ?>,
             object_category: "form_encounter",
             object_id: <?php echo htmlspecialchars($encounter, ENT_NOQUOTES); ?>
             }
             );
             });
             
             $("#med_reconc_perf").click(function() {
             if ($('#med_reconc_perf').attr('checked')) {
             var mode = "complete";
             }
             else {
             var mode = "uncomplete";
             }
             top.restoreSession();
             $.post("<?php echo $GLOBALS['webroot'] ?>/library/ajax/amc_misc_data.php",
             {amc_id: "med_reconc_amc",
             complete: true,
             mode: mode,
             patient_id: <?php echo htmlspecialchars($pid, ENT_NOQUOTES); ?>,
             object_category: "form_encounter",
             object_id: <?php echo htmlspecialchars($encounter, ENT_NOQUOTES); ?>
             }
             );
             });
             
             // $(".deleteme").click(function(evt) { deleteme(); evt.stopPropogation(); });
             
             var GotoForm = function(obj) {
             var parts = $(obj).attr("id").split("~");
             top.restoreSession();
<?php if ($GLOBALS['concurrent_layout']): ?>
                                 parent.location.href = "<?php echo $rootdir; ?>/patient_file/encounter/view_form.php?formname=" + parts[0] + "&id=" + parts[1];
<?php else: ?>
                                 top.Main.location.href = "<?php echo $rootdir; ?>/patient_file/encounter/view_form.php?formname=" + parts[0] + "&id=" + parts[1];
<?php endif; ?>
             }
             });*/

    </script>

</html>
